home *** CD-ROM | disk | FTP | other *** search
- Path: ivan.iecc.com!not-for-mail
- From: stevec@pact.srf.ac.uk (Stephen Clarke)
- Newsgroups: comp.compilers,comp.std.c
- Subject: Re: Aliasing in ISO C
- Followup-To: comp.std.c
- Date: 14 Feb 1996 21:35:36 -0500
- Organization: University of Bristol, England
- Sender: johnl@iecc.com
- Approved: compilers@ivan.iecc.com
- Message-ID: <96-02-167@comp.compilers>
- References: <96-01-037@comp.compilers> <96-02-082@comp.compilers> <96-02-116@comp.compilers>
- NNTP-Posting-Host: localhost.iecc.com
- Keywords: C, optimize, standards
-
- Ronald F. Guilmette (rfg@monkeys.com) wrote:
- : The C standard is pretty clear in saying that in the following
- : function, it is permissible to avoid the second indirection and load
- : from *p1... assuming that you still have the value previously loaded
- : from *p1 in a register somewhere:
-
- : volatile int i;
- : volatile char ch1, ch2;
-
- : void foobar (char *p1, int *p2)
- : {
- : ch1 = *p1;
- : *p2 = i;
- : ch2 = *p1;
- : }
-
- : In other words, the C standard is pretty clear in saying that C only
- : supports aliasing of (i.e. multiple pointers to) ``compatible'' (which
- : in practice usually means ``identical'') types. In other cases, the C
- : standard makes few guarantees.
-
- If I understand correctly, the part of the standard you are referring
- to is 6.3 Expressions, where rules are given for the type of the
- lvalue used to access an object's stored value ... but this section
- allows any object to be accessed using a character type, so it seems
- to me that *p1 could access an object of any type, including int,
- which means that *p1 could access the same object as *p2.
-
- This is just an unfortunate choice of types in the example. Given
-
- volatile int i;
- volatile long la, lb;
-
- void foobar (long *p1, int *p2)
- {
- la = *p1;
- *p2 = i;
- lb = *p1;
- }
-
- I agree with you, though I've never been brave enough take advantage
- of these aliasing restrictions in the compiler I work on!
-
- Steve.
- (Follow-ups to comp.std.c.)
- --
- --------------
- Stephen Clarke,
- PACT (Partnership in Advanced Computer Technologies)
- Email: stevec@pact.srf.ac.uk
- Mail : 10 Priory Road, Clifton, Bristol, BS8 1TU. UK.
- Phone: +44 117 970 7188, Fax +44 272 707 171.
- --
- Send compilers articles to compilers@iecc.com,
- meta-mail to compilers-request@iecc.com.
-